<!-- 
此组件初始化时不会自动加载数据，请在mounted中 this.$refs.[].initData()
如果放在dialog里面的吗，请在dialog的open事件中用this.$nextTick进行加载
 -->
<template>
  <div>
    <list id-key="id" ref="list" :disabled="disabled" expand-all-row show-index index-column-width="50px" :show-checkbox="showCheckbox"
      :query-params="queryParams" :expand-query="expandQuery" :page="false" :data="data" custom-get-data
      @get-data="onGetData">
      <template #toolbar-left>
        <slot name="toolbar-left"></slot>
      </template>
      <template #query>
        <div>
          <el-form-item label="名称">
            <el-input v-model.trim="queryParams.name" clearable></el-input>
          </el-form-item>
          <el-form-item label="类型">
            <el-select v-model="queryParams.types" clearable multiple collapse-tags>
              <el-option label="组" :value="1"></el-option>
              <el-option label="部门" :value="2"></el-option>
              <el-option label="公司" :value="4"></el-option>
              <el-option label="区域" :value="8"></el-option>
              <el-option label="业务版块" :value="16"></el-option>
              <el-option label="集团总部" :value="32"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label='返回父级' prop='includeParent'>
            <el-switch v-model="queryParams.includeParent" >
            </el-switch>
          </el-form-item>
          <el-form-item label='返回子级' prop='includeChildren'>
            <el-switch v-model="queryParams.includeChildren" >
            </el-switch>
          </el-form-item>
        </div>
        <div>
          <el-form-item label="ID列表">
            <el-input v-model="queryParams.idString" placeholder="ID，以,或空格分隔" clearable
              style="width:800px;max-width:none"></el-input>
          </el-form-item>
        </div>
      </template>
      <template #column>
        <el-table-column prop="name" label="组织名称" min-width="150">
          <template v-slot="{ row }">
            {{ row.name }}
            <el-tag type="danger" v-show="row.isDeleted">删除</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="typeName" width="100" label="类型" align="center" />
        <el-table-column prop="id" width="300" label="ID" />
        <!-- <el-table-column width="120" label="菜单权限">
          <template v-slot="{row}">
            <el-tag v-if="row.hasRead">读</el-tag>
            <el-tag v-if="row.hasWrite">写</el-tag>
            <el-tag v-if="row.hasReview">审核</el-tag>
          </template>
        </el-table-column> -->
        <!-- slot[column] -->
        <slot name="column"></slot>
        <!--/ slot[column]-->
      </template>
    </list>
  </div>
</template>
<script>
import listMixin from "@/mixins/list";
import list from "@/components/common/list";
import api from "@/api/platform/organizationUnit";
export default {
  mixins: [listMixin],
  components: {
    list
  },
  props: {},
  data() {
    return {
      data: [],
      //查询条件字段
      queryParams: {
        name: ""
      },
      sourceData: []
    };
  },
  methods: {
    async onGetData(params) {
      this.$refs.list.loading();
      let res = await api.getList(params);
      this.$refs.list.loading(false);
      if (res.code != 0) {
        return;
      }
      this.sourceData = res.data;
      this.data = this.$commonJs.toTreeData(res.data);
    }
  }
};
</script>